package com.edu.controller.front;

import com.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.entity.Course;
import com.edu.entity.Teacher;
import com.edu.service.CourseService;
import com.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

	@Autowired
	private TeacherService teacherService;

	@Autowired
	private CourseService courseService;

	@GetMapping("/getTeacherFrontList/{page}/{limit}")
	public R getTeacherFrontList(@PathVariable long page, @PathVariable long limit){

		Page<Teacher> pageTeacher = new Page<>(page,limit);
		Map<String,Object> map = teacherService.getTeacherFrontList(pageTeacher);
		return R.ok().data(map);
	}

	@GetMapping("/getTeacherFrontInfo/{teacherId}")
	public R getTeacherFrontInfo(@PathVariable String teacherId){

		//1 根据讲师id查询讲师基本信息
		Teacher teacher = teacherService.getById(teacherId);

		//2 根据讲师id查询课程信息
		QueryWrapper<Course> wrapper = new QueryWrapper<>();
		wrapper.eq("teacher_id",teacherId);
		List<Course> courseList = courseService.list(wrapper);

		return R.ok().data("teacher",teacher).data("courseList",courseList);
	}
}
